import { Component } from '@angular/core';
import { Platform, NavController, AlertController, NavParams, App } from 'ionic-angular';
import { PubApi } from '../../providers/pubapi';


import { Fun } from '../../providers/fun';
import { returntaskPage } from '../returntask/returntask';//自由流程审批退回页面
declare var $,userData;

@Component({
    selector: 'page-approvaldetail',
    templateUrl: 'approvaldetail.html'
})


export class approvaldetailPage extends Fun {
    public title: any = "进行段落首行文字缩进";//审批内容标题
    public content: any = "我们利用DIV CSS text-indent进行段落首行文字缩进,DIVCSS5为大家介绍text-indent缩进语法结构,并通过案例示范图例教大家实现对文段首缩进样式";//审批内容
    //  public EditDate:any;//新闻编辑日期
    public Opinion: any;//批注
    public WhetherAgree: any //是否同意
    public data: any;
    public model: any;
    public fixed: boolean = true;  //是否是固定流程
    public agree: boolean = true; //是否同意
    user: any;//下一步处理者
    dealc: any;//处理类型
    constructor(public platform: Platform, public alertCtrl: AlertController, public navCtrl: NavController, public navParams: NavParams, public appCtrl: App, public pubapi: PubApi) {
        super(alertCtrl);
        var that = this;
        platform.ready().then(() => {
            // this.model = navParams.get("items");
            // this.title = this.model.Title;
            this.pubapi.get("Users/GetAll", function (res) {
                that.user = res.data;
            })
            // this.content = //this.model.Description;
        });
    }

    ionViewDidEnter() {
        //this.showAlert("我们利用DIV CSS text-indent进行段落首行文字缩进");
        $('#cityDuoXuan').hsCheckData({
                isShowCheckBox: true, //默认为false
                minCheck: 1,//默认为0，不限最少选择个数
                maxCheck: 0,//默认为0，不限最多选择个数
                data: userData
            });

    }
    approvalsubmit() {
        var that = this;
        if (!this.fixed) {
            //自由流程
            if (this.agree) {
                 let addmodel:any;
                this.pubapi.get("FormData/SeeFlowTaskDtlPartial", function (res) {
                   addmodel = res.data;
                   that.model.FlowTasks.push(addmodel);
                })

                this.pubapi.post("FormData/AddFlowTask", this.model, function (res) {
                    let r = res.data;
                })

            }
            else {
                //自由流程退回
                this.navCtrl.push(returntaskPage, {
                    model: this.model, modeltask: this.model.FlowTasks
                });
                // this.pubapi.post("FormData/PhoneApprovel", this.model, function (res) {
                //     let r = res.data;
                // })

            }
        }
        else {
                let that=this;
            //固定流程
            if (this.agree) {
                //SeeFlowTaskDtlPartial 获取增加的model 原型
                let addmodel:any;
                this.pubapi.get("FormData/SeeFlowTaskDtlPartial", function (res) {
                   addmodel = res.data;
                   that.model.FlowTasks.push(addmodel);
                })

                this.pubapi.post("FormData/AddFlowTask", this.model, function (res) {
                    let r = res.data;
                })

            }
            else {
                //固定流程退回
                let returntype = that.model.Flow.Steps.Behaivor.ReturnType;
                if (returntype == "不可退回") {
                    this.showAlert("不可以退回！");
                }
                else if (returntype == "退回前一步") {
                    this.pubapi.post("FormData/AddBackFlowTask", this.model, function (res) {
                        let r = res.data;
                    })

                }
                else {
                    var m = this.model.
                        this.pubapi.post("FormData/AddBackFlowTask", this.model, function (res) {
                            let r = res.data;
                        })

                }



            }

        }
    }
}

